<?php
/**
 * Created by 深圳市丹宏昊天电子商务有限公司.
 * 作 者: sqingwen
 * 日 期: 2016/12/15
 * 批量单列表页面
 */
?>
<link rel="stylesheet" href="<?= base_url() . 'resource/layui/css/layui.css' ?>" media="all">
<script type="text/javascript" src="<?= base_url() . 'resource/layui/layui.js' ?>" charset="utf-8"></script>
<script type="text/javascript" src="<?= base_url() . 'resource/js/layer/layer.js' ?>" charset="utf-8"></script>
<style>
    s {
        font-style: normal
    }

    .ttips img {
        vertical-align: middle;
    }
</style>

<?php
/**
 * Created by 深圳市丹宏昊天电子商务有限公司.
 * 作 者: sqingwen
 * 日 期: 2016/12/15
 * 批量单列表页面
 */
?>
<link rel="stylesheet" href="<?= base_url() . 'resource/layui/css/layui.css' ?>" media="all">
<script type="text/javascript" src="<?= base_url() . 'resource/layui/layui.js' ?>" charset="utf-8"></script>
<script type="text/javascript" src="<?= base_url() . 'resource/js/jquery.PrintArea.js' ?>"></script>


<style>
    s {
        font-style: normal
    }

    .layui-input, .layui-textarea {
        width: 93%;
    }

    .btnSearch {
        line-height: 35px;
        height: 35px;
        padding: 0 15px;
    }

    .layui-table td, .layui-table th {
        padding: 9px 6px;
    }
    a {
    color: #0a8e61;
}
</style>
<!--菜单 start-->
<?php $this->load->view('defaults/common/left');?>
<!--菜单 end-->
<div id="content">
    <div class="page-header">
        <div class="container-fluid">
          <h1>维修包裹列表</h1>
          <?=$this->breadcrumb->generateHTML();?>
        </div>
    </div>
    <div class="container-fluid">
        <div class="panel panel-default">
            <div class="panel-heading">
                <h3 class="panel-title"><i class="fa fa-list"></i>维修包裹列表</h3>
            </div>
            <div class="panel-body">
                <div class="well" style="padding:0 19px;">
                  <div class="row">
                    <form action="" method="get">
                        <div class="col-sm-4">
                            <div class="form-group">
                                <label class="control-label">请输入包裹单号/维修单号/来货单号/SKU</label>
                                <input class="form-control" name="searchOrderNum" class="layui-input" type="text" placeholder="请输入包裹单号/维修单号/来货单号/SKU" value="<?= isset($_GET['searchOrderNum']) ? $_GET['searchOrderNum'] : '' ?>">
                            </div>
                        </div>
                   
                        <div class="col-sm-8">
                            <div class="form-group" style="padding-top: 35px;">
                                <button class="btn btn-primary" class="layui-btn btnSearch"><i class="fa fa-search"></i>&nbsp;<?= lang('l_60');//立即查询 ?></button>
                            </div>
                        </div>
                    </form>
                  </div>
                </div>
                <div class="table-responsive">
                    <table class="layui-table" lay-skin="line">
                            <thead>
                            <tr>

                                <th><input type="checkbox" id="cbk_multi_ship"><label for="cbk_multi_ship">全选/反选</label>
                                    &nbsp;包裹号
                                </th>
                                <th>维修单号码</th>
                                <th>合并时间</th>
                                <th>完成程度</th>
                                <th style="display:none;">维修师</th>
                                <th>操作&nbsp;
                                    <button class="layui-btn layui-btn-primary btn_do_shipping">批量发货</button>
                                </th>
                            </tr>
                            </thead>
                            <tbody>
                            <?php foreach ($list as $key => $val): ?>
                                <?php
                                $arr_pids = explode(',' , $val['pids']);
                                $pids = '';
                                foreach ($arr_pids as $v) {
                                    $pids .= $v . ', ';
                                }
                                $pids = rtrim($pids , ", ")
                                ?>
                                <tr>
                                    <td><input type="checkbox" name="cbk_ship_item" value="<?= $val['num'] ?>"
                                               class="cbk_ship_item"
                                               id="cf_<?= $val['id'] ?>"> <label
                                                for="cf_<?= $val['id'] ?>"><?= $val['num'] ?></td>
                                    <td>
                                        <a href="javascript:void(0)"
                                           onclick="layer.alert('<?= $val['order_num'] ?>')">查看</a>
                                    </td>
                                    <td><?= date("Y-m-d h:i:s" , $val['add_time']) ?></td>
                                    <td><?= round((count($arr_pids) - intval($val['nofinish'])) / count($arr_pids) * 100 , 2) ?>
                                        %【共<?= count($arr_pids) ?>件，<?= $val['nofinish'] ?>件未修，<?= $val['cnt_ship'] ?>
                                        件已发货】
                                    </td>
                                    <td style="display:none;"><?= $val['tec'] ?></td>
                                    <td>
                                        <button class="layui-btn layui-btn-primary btnMerge"
                                                dt-mpid="<?= $val['id'] ?>" dt-pknum="<?= $val['num'] ?>"
                                                dt-et="<?= $val['end_time'] ?>">
                                            <i class="layui-icon">&#xe608;</i> <s>开始维修</s>
                                        </button>

                                        <button class="layui-btn layui-btn-primary"
                                                onclick="layer.alert('<?= $pids ?>', {title: '<?= $val['num'] ?>所属PID'})">
                                            <i class="layui-icon">&#xe615;</i> <s>查看PID</s>
                                        </button>
                                        <button class="layui-btn layui-btn-primary btnSetTec"
                                                dt-num="<?= $val['num'] ?>" style="display:none;">
                                            <i class="layui-icon">&#xe608;</i> <s>分配维修师</s>
                                        </button>

                                        <button class="layui-btn layui-btn-primary btnShowImei"
                                                dt-num="<?= $val['num'] ?>">
                                            <i class="layui-icon">&#xe615;</i> <s>查看识别码</s>
                                        </button>

                                        <button class="layui-btn layui-btn-primary btn_shipping"
                                                dt-pknum="<?= $val['num'] ?>">
                                            <i class="layui-icon">&#xe609;</i>
                                            <s>发货</s>
                                        </button>


                                    </td>
                                </tr>

                            <?php endforeach; ?>
                            </tbody>
                        </table>
                    <?php if($show_pages):?>
                    <div class="page">
                        <?=$show_pages?>
                    </div>
                    <?php endif;?>
                </div>
            </div>
        </div>
    </div>

<style type="text/css">
    #div_load_inp_unpkqc_accessories li, #div_load_inp_unpkqc_fault li, #div_load_inp_repair_item li {
        width: 32%;
        float: left;
    }

    #ttbcc td {
        border: 1px solid #e3e3e3;
    }
</style>
<!-- 遮罩层 begin -->
<div id="overlay"></div>
<!-- 遮罩层 end -->
<div id="id_unpkqc_accessories" class="id_show_div"
     style="width:400px;height:150px;z-index: 99999;background:#f4f4f4;border:2px solid #fff;position:absolute;display:none;top:300px;padding:10px;overflow-y: scroll;">
    <div>
        <label style="float:left;">Choose Accessories</label>
        <span style="color:#fff;float:right;background-color: #db3652;padding:0 4px;border-radius:50%;cursor: pointer;"
              onclick="$('#id_unpkqc_accessories').hide();">×</span></div>
    <div style="width:99%;clear: both;height:10px;"></div>
    <div id="div_load_inp_unpkqc_accessories">

    </div>
</div>

<div id="id_unpkqc_fault" class="id_show_div"
     style="width:400px;height:150px;z-index: 99999;background:#f4f4f4;border:2px solid #fff;position:absolute;display:none;top:300px;padding:10px;overflow-y: scroll;">
    <div>
        <label style="float:left;">Choose Fault</label>
        <span style="color:#fff;float:right;background-color: #db3652;padding:0 4px;border-radius:50%;cursor: pointer;"
              onclick="$('#id_unpkqc_fault').hide();">×</span></div>
    <div style="width:99%;clear: both;height:10px;"></div>
    <div id="div_load_inp_unpkqc_fault">

    </div>
</div>

<div id="id_repair_item" class="id_show_div"
     style="width:400px;height:150px;z-index: 99999;background:#f4f4f4;border:2px solid #fff;position:absolute;display:none;top:300px;padding:10px;overflow-y: scroll;">
    <div>
        <label style="float:left;">Choose Items</label>
        <span style="color:#fff;float:right;background-color: #db3652;padding:0 4px;border-radius:50%;cursor: pointer;"
              onclick="$('#id_repair_item').hide();">×</span></div>
    <div style="width:99%;clear: both;height:10px;"></div>
    <div id="div_load_inp_repair_item">

    </div>
</div>
<!-- 质保类型 begin -->
<div id="id_unpkqc_warranty_type" class="id_show_div"
     style="width:150px;height:50px;z-index: 99999;background:#f4f4f4;border:2px solid #fff;position:absolute;display:none;top:300px;padding:10px;overflow-y: scroll;">
    <div>

        <span style="color:#fff;float:right;background-color: #db3652;padding:0 4px;border-radius:50%;cursor: pointer;"
              onclick="$('#id_unpkqc_warranty_type').hide();">×</span></div>
    <div style="clear: both">
        <input type="radio" value="1" id="rad_warranty_type_1" name="rad_warranty_type"/><label
                for="rad_warranty_type_1" style="font-weight: normal">保外/out of warranty</label><br/>
        <input type="radio" value="2" id="rad_warranty_type_2" name="rad_warranty_type"/><label
                for="rad_warranty_type_2" style="font-weight: normal">保内/with in warranty</label>
    </div>
</div>
<!-- 质保类型 end -->
<!-- 外观状况 begin -->
<div id="id_unpkqc_exterior" class="id_show_div"
     style="width:150px;height:100px;z-index: 99999;background:#f4f4f4;border:2px solid #fff;position:absolute;display:none;top:300px;padding:10px;overflow-y: scroll;">
    <div>

        <span style="color:#fff;float:right;background-color: #db3652;padding:0 4px;border-radius:50%;cursor: pointer;"
              onclick="$('#id_unpkqc_exterior').hide();">×</span></div>
    <div style="clear: both">
        <input type="radio" value="1" id="rad_unpkqc_exterior_1" name="rad_unpkqc_exterior"/><label
                for="rad_unpkqc_exterior_1" style="font-weight: normal">全新/brand new</label><br/>
        <input type="radio" value="2" id="rad_unpkqc_exterior_2" name="rad_unpkqc_exterior"/><label
                for="rad_unpkqc_exterior_2" style="font-weight: normal">九成新/90%</label><br/>

        <input type="radio" value="3" id="rad_unpkqc_exterior_3" name="rad_unpkqc_exterior"/><label
                for="rad_unpkqc_exterior_3" style="font-weight: normal">五成新/50%</label><br/>
        <input type="radio" value="4" id="rad_unpkqc_exterior_4" name="rad_unpkqc_exterior"/><label
                for="rad_unpkqc_exterior_4" style="font-weight: normal">严重损坏/bad</label><br/>

    </div>
</div>
<!-- 外观状况 end -->

<!-- 是否质保 begin -->
<div id="id_tech_is_warranty" class="id_show_div"
     style="width:150px;height:50px;z-index: 99999;background:#f4f4f4;border:2px solid #fff;position:absolute;display:none;top:300px;padding:10px;overflow-y: scroll;">
    <div>

        <span style="color:#fff;float:right;background-color: #db3652;padding:0 4px;border-radius:50%;cursor: pointer;"
              onclick="$('#id_tech_is_warranty').hide();">×</span></div>
    <div style="clear: both">
        <input type="radio" value="0" id="rad_tech_is_warranty_0" name="rad_tech_is_warranty"/><label
                for="rad_tech_is_warranty_0" style="font-weight: normal">否/No</label><br/>
        <input type="radio" value="1" id="rad_tech_is_warranty_1" name="rad_tech_is_warranty"/><label
                for="rad_tech_is_warranty_1" style="font-weight: normal">是/Yes</label>
    </div>
</div>
<!-- 是否质保 end -->

<!-- 出库质检是否合格 begin -->
<div id="id_owh_qua_status" class="id_show_div"
     style="width:150px;height:50px;z-index: 99999;background:#f4f4f4;border:2px solid #fff;position:absolute;display:none;top:300px;padding:10px;overflow-y: scroll;">
    <div>

        <span style="color:#fff;float:right;background-color: #db3652;padding:0 4px;border-radius:50%;cursor: pointer;"
              onclick="$('#id_owh_qua_status').hide();">×</span></div>
    <div style="clear: both">
        <input type="radio" value="1" id="rad_owh_qua_status_1" name="rad_owh_qua_status"/><label
                for="rad_owh_qua_status_1" style="font-weight: normal">合格/yes</label><br/>
        <input type="radio" value="0" id="rad_owh_qua_status_0" name="rad_owh_qua_status"/><label
                for="rad_owh_qua_status_0" style="font-weight: normal">不合格/no</label>
    </div>
</div>
<!-- 出库质检是否合格 end -->


<!-- 合并的弹出层 begin-->
<div id="main_merge">
    <div style="width:934px;position: fixed;margin: 0;margin-top:-13px;padding-top:13px;border-bottom: 2px dotted #e3e3e3;height: 105px;margin-left: -20px;background:#fff;line-height: 30px;z-index: 150;">
        <fieldset class="layui-elem-field" style="margin-top:20px; width:934px;margin:0 auto;">
            <legend>包裹单号 - <em id="pknum"></em></legend>
            <div class="layui-field-box">

                <button class="layui-btn layui-btn-radius layui-btn-normal btnExportCode">导出操作编码</button>
                <button class="layui-btn layui-btn-radius layui-btn-normal btnExportTemp">导出操作模板</button>
                <script type="text/javascript">
                    $('.btnExportTemp').click(function () {
                        uri = '<?= blang_url('orders/Multi/DoExportTemp') ?>?pkNum=' + $('#pknum').text();
                        window.location.href = uri;
                    });
                    $('.btnExportCode').click(function () {
                        top.location.href = $('#hidCatId').val();
                        // layer.tips("还没有操作编码所以没有下载内容", ".btnExportCode");
                    });

                </script>

                <button class="layui-btn layui-btn-danger add_wayboll_close" style="float: right;">关闭</button>
                <button class="layui-btn layui-btn-normal btnSavvve" style="float: right;">保存</button>


                <input type="text" name="txtTime" id="txtTime" placeholder="耗时总计(工时)"
                       style="   border: 1px solid #e3e3e3;float: right;height: 25px;padding-left: 7px;width: 100px;"/>&nbsp;
                <input type="hidden" name="hidNum" id="hidNum" value=""/>
            </div>
        </fieldset>

    </div>

    <table class="layui-table" lay-skin="line" style="margin-top:135px;">

        <tbody id="pk_details">
        <tr id="inner_tb">
            <td colspan="3"></td>
        </tr>
        </tbody>

    </table>
</div>
<input type="hidden" id="hidCatId" value="0"/>
<!-- 合并的弹出层 end-->

<!-- 发货的弹出层 begin-->
<div class="div_shipping">
    <span style="float:right;padding:5px;cursor: pointer;color: #db3652;"
          onclick="$('.div_shipping').hide();hideOverlay();$('#txt_shipping_num').val('');"><i class="layui-icon">&#x1007;</i></span>
    <fieldset class="layui-elem-field" style="margin-top:20px; width:434px;margin:0 auto;">
        <legend>发货</legend>
        <div class="layui-field-box">
            <div style="    width: 404px;height: 50px;overflow-y: scroll;background: #f4f4f4;" class="isOkShipping">

            </div>
            <hr/>

            物流单号：<input type="text" name="txt_shipping_num" id="txt_shipping_num">&nbsp;
            <button class="layui-btn layui-btn-primary btn_shipping_do">确定</button>
            <input type="hidden" id="hid_shipping_pk_nums" value="0">

        </div>

    </fieldset>

    <div style="width: 435px;margin: 0 auto;margin-top: 12px;">
        <h2>已经发货的产品:</h2>
        <table style="width:434px;" id="ttbcc">
            <thead>
            <tr id="dt-shipping">
                <th style="height: 22px;">
                    OrderNum
                </th>
                <th style="height: 22px;">
                    PID
                </th>
                <th style="height: 22px;">
                    ShippingNum
                </th>
                <th style="height: 22px;">
                    ShippingTime
                </th>
            </tr>
            </thead>
            <tbody id="ttbody">

            </tbody>
        </table>
    </div>


</div>
<!-- 发货的弹出层 end -->


<style type="text/css">

    .div_shipping {
        width: 456px;
        min-height: 380px;
        display: none;
        background: #fff;
        position: fixed;
        top: 50%;
        left: 50%;
        margin: -190px 0 0 -228px;
        z-index: 120;
    }

    #main_merge {
        display: none;
        width: 900px;
        height: 600px;
        background: #fff;
        padding: 13px 21px;
        box-shadow: 0 0 3px #000;
        position: fixed;
        top: 50%;
        left: 50%;
        margin: -301px 0 0 -460px;
        z-index: 120;
        overflow: auto;
    }

    .layui-table td {
        padding: 3px 15px;
    }

    #main_merge input[type=text] {
        color: #333;
        border: 1px solid #e3e3e3;
        background: none;
        width: 85px;
        margin-left: 10px;
    }

    /* 半透明的遮罩层 */
    #overlay {
        background: #000;
        filter: alpha(opacity=50); /* IE的透明度 */
        opacity: 0.5; /* 透明度 */
        display: none;
        position: absolute;
        top: 0px;
        left: 0px;
        width: 100%;
        height: 100%;
        z-index: 100; /* 此处的图层要大于页面 */
        display: none;
    }

    .par {
        width: 79px;
        text-align: right;
        padding-right: 21px;
    }

    .cbzj {
        width: 88px;
        font-size: 9px;
        line-height: 12px;
        border-right: 1px solid #e3e3e3;
        white-space: normal;
        padding: 0;
    }

    .wxs {
        width: 88px;
        font-size: 9px;
        line-height: 12px;
        border-right: 1px solid #e3e3e3;
    }

    .ckzj {
        width: 88px;
        font-size: 9px;
        line-height: 12px;
        border-right: 1px solid #e3e3e3;
        white-space: normal;
        border-bottom: none;
        padding: 0
    }

    .layui-layer-content > div > span {
        width: 33%;
        float: left;
    }

    .layui-table td, .layui-table th {
        padding: 9px 6px;
    }

    #div_load_inp_unpkqc_accessories label, #div_load_inp_unpkqc_fault label, #div_load_inp_repair_item label {
        font-weight: normal
    }
</style>
<script type="text/javascript">

    $('.btnSetTec').click(function () {
        var pknum = $(this).attr('dt-num');
        var ttmp = ' <fieldset class="layui-elem-field" style="width: 90%;margin: 0 auto;"><legend>设置维修师</legend><div class="layui-field-box"><select id="selChTec" name="celChkTec" style="width:205px;height:35px;">';
        ttmp = ttmp + '<option value="0">请选择维修师</option>';
        <?php foreach ($users as $k => $v) { ?>
        ttmp = ttmp + '<option value="<?= $v['id'] ?>"><?= $v['chart'] ?> <?= $v['name'] ?></option>';
        <?php } ?>
        ttmp = ttmp + '</select><button class="layui-btn" style="margin-left: 5px;height: 35px;margin-top: -3px;width: 46px;line-height: 36px;" onclick="setTec(' + pknum + ')">保存</button></div></fieldset>';
        layer.open({
            type: 1,
            title: pknum,
            skin: 'layui-layer-rim', //加上边框
            area: ['320px', '180px'], //宽高
            content: ttmp
        });
    });

    //保存维维修师
    setTec = function (pknum) {
        $.ajax({
            type: "POST",
            url: '<?= blang_url('orders/Multi/ajaxSetTecId') ?>',
            async: false,
            data: {'tecid': $.trim($('#selChTec').val()), 'num': pknum},
            dataType: "json",
            success: function (data) {
                layer.msg('分配成功！');
                var t = setTimeout("window.location.reload(true)", 1000);
            }
        });
    }
    $('.btnSavvve').click(function () {

        var ser = ($('#pk_details input').serialize());
        //**************
        $.ajax({
            type: "POST",
            url: '<?= blang_url('orders/Multi/ajaxSaveMerge') ?>',
            data: {str: ser},
            dataType: "text",
            success: function (data) {
                layer.msg("添加成功！");
                $('#main_merge').hide();
                hideOverlay();
                window.location.reload(true);
            }
        });

        $.ajax({
            type: "POST",
            url: '<?= blang_url('orders/Multi/ajaxSaveMergeTime') ?>',
            async: false,
            data: {'et': $.trim($('#txtTime').val()), 'num': $('#hidNum').val()},
            dataType: "json",
            success: function (data) {

            }
        });

        //**************

        //up_pro_sta
    });

    //合并按钮 begin
    $('.btnMerge').click(function () {
        $('#pknum').text($(this).attr('dt-pknum'));
        $('#hidNum').val($(this).attr('dt-pknum'));
        $('#txtTime').val($(this).attr('dt-et'));
        showOverlay();
        $('#main_merge').show();
        //alert($(this).attr('dt-mpid'));
        loadDetails($(this).attr('dt-mpid'));
    });
    //合并按钮 end

    //关闭 begin
    $('.add_wayboll_close').click(function () {
        $('#main_merge').hide();
        hideOverlay();
        $('#pk_details .tr_show').remove();//清理所有之前的旧数据
        window.location.reload(true);
    });
    //关闭 endpk_details


    //加载合并包裹 begin
    loadDetails = function (pkId) {
        $.ajax({
            type: "POST",
            url: '<?= blang_url('orders/Multi/ajaxGetProductsBypkId?' . time()) ?>',
            data: {
                'pkid': pkId
            },
            dataType: "json",
            success: function (data) {

                if (data.length > 0) {

                    $('#hidCatId').val('/resource/multi-tp/' + data[0].category_id + '.xls');
                    var tp;
                    for (var i = 0; i < data.length; i++) {
                        check1 = '';
                        check2 = '';
                        cck = '';
                        dis = '';
                        if (data[i].is_finnish == 1) {
                            check1 = 'selected="selected"';
                            //cck = 'disabled="disabled"';
                            //dis = 'style="display:none;"'
                        } else {
                            check2 = 'selected="selected"';
                            cck = '';
                        }
                        tp = '<tr class="tr_show"><td>' + (i + 1) + ' &nbsp;&nbsp;PID:' + data[i].id + ' &nbsp;&nbsp;IMEI:' + data[i].imei + '  &nbsp;&nbsp;SKU:' + data[i].sku + '&nbsp;&nbsp;Brand:' + data[i].product_brand + '&nbsp;&nbsp;Model:' + data[i].product_model + '  <select style="float:right" class="cbkPstatus" name="cbkPStatus" ' + cck + ' dt-pid="' + data[i].id + '"><option value="1" ' + check1 + '>修复完成</option><option value="0" ' + check2 + '>未能修复</option></select> </td></tr><tr><td>Desc:' + data[i].defectDes + '</td></tr><tr><td style="border-bottom:2px dotted #ff6600">'
                            + '<table><tr>'
                            + '<td class="par">拆包质检:</td><td style="display: none;">产品状态<input type="text" value="' + (data[i].unpkqc_pro_status) + '" name="up_pro_sta" maxlength="255"></td>'
                            + '<td>质保类型<input type="text" ' + cck + ' value="' + (data[i].unpkqc_warranty_type) + '" name="up_warranty_type" maxlength="255"><a class="a_warranty_type" href="javascript:void(0)" ' + dis + '><img src="/resource/images/arrow_carrot_down.png"/></a></td>'
                            + '<td>外观状况<input type="text" ' + cck + '  value="' + (data[i].unpkqc_exterior) + '" name="up_exterior" maxlength="255"><a class="a_unpkqc_exterior" href="javascript:void(0)" ' + dis + '><img src="/resource/images/arrow_carrot_down.png"/></a></td>'
                            + '<td>随机附件<input type="text" ' + cck + '  value="' + (data[i].unpkqc_accessories) + '" name="up_acce" maxlength="255"><a dt-cat="' + data[i].category_id + '" class="ttips a_unpkqc_accessories" href="javascript:void(0)" ' + dis + '><img src="/resource/images/arrow_carrot_down.png"/></a></td>'
                            + '<td>故障编号<input type="text" ' + cck + '  value="' + (data[i].unpkqc_fault) + '" name="up_mal_num" maxlength="255"><a  dt-cat="' + data[i].category_id + '" class="ttips a_unpkqc_fault" href="javascript:void(0)" ' + dis + '><img src="/resource/images/arrow_carrot_down.png"/></a></td>'
                            + '<td style="display:none;">备注<input type="text" value="' + (data[i].unpkqc_remark) + '" name="up_remark" maxlength="255"></td>'
                            + '</tr><tr>'
                            + '<td class="par">维修师:</td><td style="display: none;">产品状态<input type="text" value="' + (data[i].repair_pro_status) + '" name="tech_pro_sta" maxlength="255"></td>'
                            + '<td>是否质保<input type="text" ' + cck + '  value="' + (data[i].repair_is_warranty) + '" name="tech_is_warranty" maxlength="255"><a class="a_tech_is_warranty" href="javascript:void(0)" ' + dis + '><img src="/resource/images/arrow_carrot_down.png"/></a></td>'
                            + '<td>维&nbsp;修&nbsp;项<input type="text" ' + cck + '  value="' + (data[i].repair_repair_item) + '" name="tech_items" maxlength="255"><a dt-cat="' + data[i].category_id + '" class="ttips a_repair_item" href="javascript:void(0)" ' + dis + '><img src="/resource/images/arrow_carrot_down.png"/></a></td>'
                            + '<td>添加配件<input type="text" ' + cck + '  value="' + (data[i].repair_accessories) + '" name="tech_acce" maxlength="255"></td>'
                            + '<td style="display:none;">维修师备注<input type="text" value="' + (data[i].repair_remark) + '" name="tech_remark" maxlength="255"></td>'
                            + '<td style="">&nbsp;</td>'
                            + '</tr><tr>'
                            + '<td class="par">出库质检:</td><td>合格状态<input ' + cck + '  type="text" value="' + (data[i].qc_is_qualified) + '" name="owh_qua_status" maxlength="255"><a class="a_owh_qua_status" href="javascript:void(0)" ' + dis + '><img src="/resource/images/arrow_carrot_down.png"/></a></td>'
                            + '<td>描述状况<input type="text" ' + cck + '  value="' + (data[i].qc_desc) + '" name="owh_desc" maxlength="255"></td>'
                            + '<td style="display:none;">外观状况<input type="text" value="1" name="owh_exterior" maxlength="255"></td>'
                            + '<td>随机附件<input type="text" ' + cck + '  value="' + (data[i].qc_accessories) + '" name="owh_acce" maxlength="255"><a dt-cat="' + data[i].category_id + '" class="ttips a_qc_accessories" href="javascript:void(0)" ' + dis + '><img src="/resource/images/arrow_carrot_down.png"/></a></td>'
                            + '<td>故障编号<input type="text" ' + cck + '  value="' + (data[i].qc_fault) + '" name="owh_mal_num" maxlength="255"><a  dt-cat="' + data[i].category_id + '" class="ttips a_qc_fault" href="javascript:void(0)" ' + dis + '><img src="/resource/images/arrow_carrot_down.png"/></a></td><td></td></tr><tr>'
                            + '<td style="padding:0;">出库质检备注:</td><td colspan="6"><input ' + cck + '   name="owh_remark" maxlength="255" style="width: 94%;background: none;border: 1px solid #e3e3e3;" value="' + (data[i].qc_remark) + '">' +
                            '<input type="hidden" value="' + data[i].id + '" name="hidPid"/>' +
                            '<input type="hidden" name="hidUnNum" value="' + data[i].unpk_num + '"><input type="hidden" name="hidPkNum" value="' + data[i].pk_num + '"></td>'
                            + '</tr></table></td></tr>';
                        $('#inner_tb').before(tp);
                    }
                    $('.cbkPstatus').change(function () {

                        $.post('<?= blang_url('orders/Multi/ajaxSetIsFinnish?') ?>', {
                            'id': $(this).attr('dt-pid'),
                            'status': $(this).val()
                        }, function () {
                            layer.msg("保存状态成功！");

                        });


                    });

                    $("#pk_details input[type='text']").keyup(function () {
                        var cnt_chart = parseInt($(this).val().length);
                        if (cnt_chart > 254) {
                            layer.msg("字符长度不能超过255！");

                        }
                    });
                    //===========================================================================================================================
                    //弹出 随机附件 begin
                    $('.a_unpkqc_accessories').click(function () {
                        var tttop = (($(this).offset().top) + 25) + 'px';
                        var ttleft = (($(this).offset().left) - 400) + 'px';
                        $('#id_unpkqc_accessories').css('top', tttop);
                        $('#id_unpkqc_accessories').css('left', ttleft);

                        var acc_index = $('.a_unpkqc_accessories').index($(this));
                        $.post('<?= blang_url('orders/Multi/ajaxLoadAcc?') ?>', {'catid': $(this).attr('dt-cat')}, function (data) {
                            $('#div_load_inp_unpkqc_accessories').html(data);
                            //设置状态 begin
                            var str_check = $('input[name="up_acce"]').eq(acc_index).val();
                            if (str_check != '') {
                                $(str_check.split(",")).each(function (i, dom) {
                                    $(":checkbox[id='iuacc_" + dom + "']").prop("checked", true);
                                });
                                $(str_check.split(" ")).each(function (i, dom) {
                                    $(":checkbox[id='iuacc_" + dom + "']").prop("checked", true);
                                });
                            }
                            //设置状态 end
                            $("input[name='inp_unpkqc_accessories']").click(function () {
                                str_accc = '';
                                $("input[name='inp_unpkqc_accessories']").each(function () {
                                    if ($(this).is(':checked')) {
                                        if (str_accc != '') {
                                            str_accc += ',';
                                        }
                                        str_accc += $(this).val();
                                    }
                                });
                                $('input[name="up_acce"]').eq(acc_index).val(str_accc);
                            });

                        }, 'text');
                        $('.id_show_div').hide();
                        $('#id_unpkqc_accessories').show();
                    });
                    //弹出 随机附件 end

                    //弹出 故障项 begin
                    $('.a_unpkqc_fault').click(function () {
                        var tttop = (($(this).offset().top) + 25) + 'px';
                        var ttleft = (($(this).offset().left) - 400) + 'px';
                        $('#id_unpkqc_fault').css('top', tttop);
                        $('#id_unpkqc_fault').css('left', ttleft);

                        var acc_index = $('.a_unpkqc_fault').index($(this));
                        $.post('<?= blang_url('orders/Multi/ajaxLoadFault?') ?>', {'catid': $(this).attr('dt-cat')}, function (data) {
                            $('#div_load_inp_unpkqc_fault').html(data);

                            //设置状态 begin
                            var str_check = $('input[name="up_mal_num"]').eq(acc_index).val();
                            if (str_check != '') {
                                $(str_check.split(",")).each(function (i, dom) {
                                    $(":checkbox[id='iufault_" + dom + "']").prop("checked", true);
                                });

                                $(str_check.split(" ")).each(function (i, dom) {
                                    $(":checkbox[id='iufault_" + dom + "']").prop("checked", true);
                                });
                            }
                            //设置状态 end

                            $("input[name='inp_unpkqc_fault']").click(function () {
                                str_accc = '';
                                $("input[name='inp_unpkqc_fault']").each(function () {
                                    if ($(this).is(':checked')) {
                                        if (str_accc != '') {
                                            str_accc += ',';
                                        }
                                        str_accc += $(this).val();
                                    }
                                });
                                $('input[name="up_mal_num"]').eq(acc_index).val(str_accc);
                            });

                        }, 'text');
                        $('.id_show_div').hide();
                        $('#id_unpkqc_fault').show();
                    });


                    //弹出 故障项 end

                    //弹出 qc随机附件 begin
                    $('.a_qc_accessories').click(function () {
                        var tttop = (($(this).offset().top) + 25) + 'px';
                        var ttleft = (($(this).offset().left) - 400) + 'px';
                        $('#id_unpkqc_accessories').css('top', tttop);
                        $('#id_unpkqc_accessories').css('left', ttleft);

                        var acc_index = $('.a_qc_accessories').index($(this));
                        $.post('<?= blang_url('orders/Multi/ajaxLoadAcc?') ?>', {'catid': $(this).attr('dt-cat')}, function (data) {
                            $('#div_load_inp_unpkqc_accessories').html(data);

                            //设置状态 begin
                            var str_check = $('input[name="owh_acce"]').eq(acc_index).val();
                            if (str_check != '') {
                                $(str_check.split(",")).each(function (i, dom) {
                                    $(":checkbox[id='iuacc_" + dom + "']").prop("checked", true);
                                });
                                $(str_check.split(" ")).each(function (i, dom) {
                                    $(":checkbox[id='iuacc_" + dom + "']").prop("checked", true);
                                });
                            }
                            //设置状态 end
                            $("input[name='inp_unpkqc_accessories']").click(function () {
                                str_accc = '';
                                $("input[name='inp_unpkqc_accessories']").each(function () {
                                    if ($(this).is(':checked')) {
                                        if (str_accc != '') {
                                            str_accc += ',';
                                        }
                                        str_accc += $(this).val();
                                    }
                                });
                                $('input[name="owh_acce"]').eq(acc_index).val(str_accc);
                            });

                        }, 'text');
                        $('.id_show_div').hide();
                        $('#id_unpkqc_accessories').show();
                    });
                    //弹出 qc随机附件 end
                    //弹出 qc故障项 begin
                    $('.a_qc_fault').click(function () {
                        var tttop = (($(this).offset().top) + 25) + 'px';
                        var ttleft = (($(this).offset().left) - 400) + 'px';
                        $('#id_unpkqc_fault').css('top', tttop);
                        $('#id_unpkqc_fault').css('left', ttleft);

                        var acc_index = $('.a_qc_fault').index($(this));
                        $.post('<?= blang_url('orders/Multi/ajaxLoadFault?') ?>', {'catid': $(this).attr('dt-cat')}, function (data) {
                            $('#div_load_inp_unpkqc_fault').html(data);

                            //设置状态 begin
                            var str_check = $('input[name="owh_mal_num"]').eq(acc_index).val();
                            if (str_check != '') {
                                $(str_check.split(",")).each(function (i, dom) {

                                    $(":checkbox[id='iufault_" + dom + "']").prop("checked", true);
                                });
                                $(str_check.split(" ")).each(function (i, dom) {

                                    $(":checkbox[id='iufault_" + dom + "']").prop("checked", true);
                                });
                            }
                            //设置状态 end
                            $("input[name='inp_unpkqc_fault']").click(function () {
                                str_accc = '';
                                $("input[name='inp_unpkqc_fault']").each(function () {
                                    if ($(this).is(':checked')) {
                                        if (str_accc != '') {
                                            str_accc += ',';
                                        }
                                        str_accc += $(this).val();
                                    }
                                });
                                $('input[name="owh_mal_num"]').eq(acc_index).val(str_accc);
                            });

                        }, 'text');
                        $('.id_show_div').hide();
                        $('#id_unpkqc_fault').show();
                    });


                    //弹出 故障项 end

                    //弹出维修项 begin
                    $('.a_repair_item').click(function () {
                        var tttop = (($(this).offset().top) + 25) + 'px';
                        var ttleft = (($(this).offset().left) - 400) + 'px';
                        $('#id_repair_item').css('top', tttop);
                        $('#id_repair_item').css('left', ttleft);

                        var acc_index = $('.a_repair_item').index($(this));
                        $.post('<?= blang_url('orders/Multi/ajaxLoadItem') ?>', {'catid': $(this).attr('dt-cat')}, function (data) {
                            $('#div_load_inp_repair_item').html(data);
                            //设置状态 begin
                            var str_check = $('input[name="tech_items"]').eq(acc_index).val();
                            if (str_check != '') {
                                $(str_check.split(",")).each(function (i, dom) {
                                    $(":checkbox[id='iuitem_" + dom + "']").prop("checked", true);
                                });
                                $(str_check.split(" ")).each(function (i, dom) {
                                    $(":checkbox[id='iuitem_" + dom + "']").prop("checked", true);
                                });
                            }
                            //设置状态 end

                            $("input[name='inp_repair_item']").click(function () {
                                str_accc = '';
                                $("input[name='inp_repair_item']").each(function () {
                                    if ($(this).is(':checked')) {
                                        if (str_accc != '') {
                                            str_accc += ',';
                                        }
                                        str_accc += $(this).val();
                                    }
                                });
                                $('input[name="tech_items"]').eq(acc_index).val(str_accc);
                            });

                        }, 'text');
                        $('.id_show_div').hide();
                        $('#id_repair_item').show();
                    });
                    //弹出维修项 end


                    //弹出质保类型 begin
                    var wt_index = 0;
                    $('.a_warranty_type').click(function () {
                        var tttop = (($(this).offset().top) + 25) + 'px';
                        var ttleft = (($(this).offset().left) - 150) + 'px';
                        $('#id_unpkqc_warranty_type').css('top', tttop);
                        $('#id_unpkqc_warranty_type').css('left', ttleft);
                        $('.id_show_div').hide();
                        $('#id_unpkqc_warranty_type').show();
                        wt_index = $('.a_warranty_type').index($(this));
                        var sstr = '';

                        //这里赋值 begin
                        if ($('input[name="up_warranty_type"]').eq(wt_index).val() != '') {
                            $("#rad_warranty_type_" + $('input[name="up_warranty_type"]').eq(wt_index).val()).attr("checked", "checked");
                        }
                        //这里赋值 end
                        $("input[name='rad_warranty_type']").click(function () {
                            sstr = $(this).val();
                            $('input[name="up_warranty_type"]').eq(wt_index).val(sstr);
                        });

                    });
                    //弹出质保类型 end


                    //弹出外观状况 begin
                    var ue_index = 0;
                    $('.a_unpkqc_exterior').click(function () {
                        var tttop = (($(this).offset().top) + 25) + 'px';
                        var ttleft = (($(this).offset().left) - 150) + 'px';
                        $('#id_unpkqc_exterior').css('top', tttop);
                        $('#id_unpkqc_exterior').css('left', ttleft);
                        $('.id_show_div').hide();
                        $('#id_unpkqc_exterior').show();
                        ue_index = $('.a_unpkqc_exterior').index($(this));
                        var sstr = '';

                        //这里赋值 begin
                        if ($('input[name="up_exterior"]').eq(ue_index).val() != '') {
                            $("#rad_unpkqc_exterior_" + $('input[name="up_exterior"]').eq(ue_index).val()).attr("checked", "checked");
                        }
                        //这里赋值 end
                        $("input[name='rad_unpkqc_exterior']").click(function () {
                            sstr = $(this).val();
                            $('input[name="up_exterior"]').eq(ue_index).val(sstr);
                        });

                    });
                    //弹出外观状况 end

                    //弹出维修师是否质保 begin
                    var tiw_index = 0;
                    $('.a_tech_is_warranty').click(function () {
                        var tttop = (($(this).offset().top) + 25) + 'px';
                        var ttleft = (($(this).offset().left) - 150) + 'px';
                        $('#id_tech_is_warranty').css('top', tttop);
                        $('#id_tech_is_warranty').css('left', ttleft);
                        $('.id_show_div').hide();
                        $('#id_tech_is_warranty').show();
                        tiw_index = $('.a_tech_is_warranty').index($(this));
                        var sstr = '';

                        //这里赋值 begin
                        if ($('input[name="tech_is_warranty"]').eq(tiw_index).val() != '') {
                            $("#rad_tech_is_warranty_" + $('input[name="tech_is_warranty"]').eq(tiw_index).val()).attr("checked", "checked");
                        }
                        //这里赋值 end
                        $("input[name='rad_tech_is_warranty']").click(function () {
                            sstr = $(this).val();
                            $('input[name="tech_is_warranty"]').eq(tiw_index).val(sstr);
                        });

                    });
                    //弹出维修师是否质保 end


                    //弹出维修师是否质保 begin
                    var oqs_index = 0;
                    $('.a_owh_qua_status').click(function () {
                        var tttop = (($(this).offset().top) + 25) + 'px';
                        var ttleft = (($(this).offset().left) - 150) + 'px';
                        $('#id_owh_qua_status').css('top', tttop);
                        $('#id_owh_qua_status').css('left', ttleft);
                        $('.id_show_div').hide();
                        $('#id_owh_qua_status').show();
                        oqs_index = $('.a_owh_qua_status').index($(this));
                        var sstr = '';

                        //这里赋值 begin
                        if ($('input[name="owh_qua_status"]').eq(oqs_index).val() != '') {
                            $("#rad_owh_qua_status_" + $('input[name="owh_qua_status"]').eq(oqs_index).val()).attr("checked", "checked");
                        }
                        //这里赋值 end
                        $("input[name='rad_owh_qua_status']").click(function () {
                            sstr = $(this).val();
                            $('input[name="owh_qua_status"]').eq(oqs_index).val(sstr);
                        });

                    });
                    //弹出维修师是否质保 end
                    //===========================================================================================================================


                } else {

                }
            },
            beforeSend: function (XMLHttpRequest) {
                $('#pk_details .tr_show').remove();//加载前清理所有之前的旧数据
                lload = layer.load(1, {shade: [0.1, '#fff']});
            },
            complete: function (XMLHttpRequest, textStatus) {
                layer.close(lload);
            }
        });
    }
    //加载合并包裹 end

    //显示imei begin
    $('.btnShowImei').click(function () {
        pkNum = $(this).attr('dt-num');
        $.post('<?= blang_url('orders/Multi/ajaxGetImeisByPkNum') ?>', {'num': pkNum}, function (data) {
            //alert(data.length);
            if (data.length == 0) {
                layer.alert("没有imei，请联系管理员！");
                return;
            }
            ttmpp = '';
            for (var i = 0; i < data.length; i++) {
                ttmpp = ttmpp + '<span>' + data[i] + '</span>';
            }
            ttmpp = '<div style="width:400px;margin:0 auto;margin-top:10px;">' + ttmpp + '</div>';
            layer.open({
                type: 1,
                skin: 'layui-layer-rim', //加上边框
                area: ['420px', '240px'], //宽高
                content: ttmpp
            });
        }, "json");

    });
    //显示imei end

    /*发货 begin-----------------------------------*/
    $('#cbk_multi_ship').change(function () {
        if ($(this).is(':checked')) {
            $('.cbk_ship_item').each(function () {
                if ($(this).is(':checked')) {
                    $(this).prop("checked", false);
                } else {
                    $(this).prop("checked", true);

                }
            });
        } else {
            $('.cbk_ship_item').each(function () {
                $(this).prop("checked", false);
            });

        }

    });


    //单个包裹发货
    $('.btn_shipping').click(function () {

        //设置维修包裹号
        // $('#hid_shipping_pk_nums').val($(this).attr('dt-pknum'));
        var pknum = $(this).attr('dt-pknum');
        $.post("<?= blang_url('orders/Multi/ajaxGetShippingProductsId') ?>", {'pknum': $(this).attr('dt-pknum')}, function (res) {
            if (res !== '') {
                $('.isOkShipping').html("发货产品（PID）：" + res);
                $('.div_shipping').show();
                $('#txt_shipping_num').focus();
                var ccctrpids = '';
                //加载已经发货的产品id
                $.post('<?= blang_url('orders/Multi/ajaxGetShippoingNum') ?>', {'num': pknum}, function (data) {
                    if (data.length > 0) {
                        trr = '';
                        for (var i = 0; i < data.length; i++) {
                            trr += "<tr><td >" + data[i].order_num + "</td><td>" + data[i].id + "</td><td>" + data[i].shipping_num + "</td><td>" + data[i].shipping_time + "</td></tr>";

                        }

                        $('#ttbody').html(trr);
                    }
                }, "json");
                //加载已经发货的产品id

                $("input[name='shipping_product']").click(function () {
                    $("input[name='shipping_product']").each(function () {
                        if ($(this).is(":checked")) {
                            if (ccctrpids != '') {
                                ccctrpids += ',';
                            }
                            ccctrpids += $(this).val();
                        }
                    });
                    $('#hid_shipping_pk_nums').val(ccctrpids);
                });

                showOverlay();
            } else {
                layer.msg("没有可以发货的产品！");
                return;
            }
        }, "text");

    });


    //批量包裹发货
    $('.btn_do_shipping').click(function () {

        var s_i_pk_nums = '';//维修包裹号集合
        var cc_cnt = 0;
        $('.cbk_ship_item').each(function () {
            if ($(this).is(':checked')) {
                if (cc_cnt == 0) {
                    s_i_pk_nums = $(this).val();
                } else {
                    s_i_pk_nums = s_i_pk_nums + ',' + $(this).val();
                }
                cc_cnt++;
            }

        });

        if (cc_cnt == 0) {
            layer.msg("您没有选择具体的维修包裹!");
            return false;
        }
        //设置维修包裹号

        $.post("<?= blang_url('orders/Multi/ajaxGetShippingProductsId') ?>", {'pknum': s_i_pk_nums}, function (res) {
            if (res !== '') {
                $('.isOkShipping').html("发货产品（PID）：" + res);
                $('.div_shipping').show();
                $('#txt_shipping_num').focus();
                //加载已经发货的产品id
                $.post('<?= blang_url('orders/Multi/ajaxGetShippoingNums') ?>', {'num': s_i_pk_nums}, function (data) {
                    if (data.length > 0) {
                        trr = '';
                        for (var i = 0; i < data.length; i++) {
                            trr += "<tr><td >" + data[i].order_num + "</td><td>" + data[i].id + "</td><td>" + data[i].shipping_num + "</td><td>" + data[i].shipping_time + "</td></tr>";

                        }

                        $('#ttbody').html(trr);
                    }
                }, "json");
                //加载已经发货的产品id
                $("input[name='shipping_product']").click(function () {
                    var ccctrpids = '';
                    $("input[name='shipping_product']").each(function () {
                        if ($(this).is(":checked")) {
                            if (ccctrpids != '') {
                                ccctrpids += ',';
                            }
                            ccctrpids += $(this).val();
                        }
                    });
                    $('#hid_shipping_pk_nums').val(ccctrpids);
                });
                showOverlay();
            } else {
                layer.msg("没有可以发货的产品！");
                return;
            }
        }, "text")
    });

    //发货按钮
    $('.btn_shipping_do').click(function () {


        $.post("<?= blang_url('orders/Multi/ajaxDoShipping') ?>", {
            'pknum': $('#hid_shipping_pk_nums').val(),
            'ship_num': $('#txt_shipping_num').val()
        }, function (res) {
            if (res) {
                layer.msg('添加物流单号成功！');
                window.location.href = location.href;
                //                $('#txt_shipping_num').val();
                //                $('.div_shipping').hide();
                //                hideOverlay();
            }
        }, "JSON");

    });

    $('#txt_shipping_num').bind('keypress', function (event) {

        if (event.keyCode == "13") {
            $.post("<?= blang_url('orders/Multi/ajaxDoShipping') ?>", {
                'pknum': $('#hid_shipping_pk_nums').val(),
                'ship_num': $('#txt_shipping_num').val()
            }, function (res) {
                if (res) {
                    layer.msg('添加物流单号成功！');
                    window.location.href = location.href;
                    //                    $('#txt_shipping_num').val();
                    //                    $('.div_shipping').hide();
                    //                    hideOverlay();
                }
            }, "JSON");
        }
    });

    /*发货 end ------------------------------------*/

    /* 显示遮罩层 */
    function showOverlay() {
        $("#overlay").height(pageHeight());
        $("#overlay").width(pageWidth());
        // fadeTo第一个参数为速度，第二个为透明度
        // 多重方式控制透明度，保证兼容性，但也带来修改麻烦的问题
        $("#overlay").fadeTo(200, 0.5);
    }

    /* 隐藏覆盖层 */
    function hideOverlay() {
        $("#overlay").fadeOut(200);
    }

    /* 当前页面高度 */
    function pageHeight() {
        return document.body.scrollHeight;
    }

    /* 当前页面宽度 */
    function pageWidth() {
        return document.body.scrollWidth;
    }


</script>

</div>